package com.xbts.web.controller.system;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.xbts.common.enums.CompanyInformationEnum;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.xbts.common.annotation.Log;
import com.xbts.common.core.controller.BaseController;
import com.xbts.common.core.domain.AjaxResult;
import com.xbts.common.enums.BusinessType;
import com.xbts.system.domain.CnCompanyInformation;
import com.xbts.system.service.ICnCompanyInformationService;
import com.xbts.common.utils.poi.ExcelUtil;
import com.xbts.common.core.page.TableDataInfo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;

/**
 * 公司信息Controller
 * @author xbts
 * @date 2023-08-28
 */
@Api("公司信息")
@RestController
@RequestMapping("/system/information")
public class CnCompanyInformationController extends BaseController {

    @Autowired
    private ICnCompanyInformationService cnCompanyInformationService;

    /**
     * 查询公司信息列表
     */
    @ApiOperation("查询公司信息列表")
    @PreAuthorize("@ss.hasPermi('system:information:list')")
    @PostMapping("/list")
    public TableDataInfo list(@RequestBody CnCompanyInformation cnCompanyInformation) {
        startPage(cnCompanyInformation);
        List<CnCompanyInformation> list = cnCompanyInformationService.selectCnCompanyInformationList(cnCompanyInformation);
        return getDataTable(list);
    }

    /**
     * 导出公司信息列表
     */
    @ApiOperation("导出公司信息列表")
    @PreAuthorize("@ss.hasPermi('system:information:export')")
    @Log(title = "公司信息", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response,@RequestBody CnCompanyInformation cnCompanyInformation) {
        List<CnCompanyInformation> list = cnCompanyInformationService.selectCnCompanyInformationList(cnCompanyInformation);
        ExcelUtil<CnCompanyInformation> util = new ExcelUtil<CnCompanyInformation>(CnCompanyInformation.class);
        util.exportExcel(response, list, "公司信息数据");
    }

    /**
     * 获取公司信息详细信息
     */
    @ApiOperation("获取公司信息详细信息")
    @ApiImplicitParam(name = "id", value = "公司信息ID", required = true, dataType = "String", paramType = "path", dataTypeClass=String.class)
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") String id) {
        return success(cnCompanyInformationService.selectCnCompanyInformationById(id));
    }


    /**
     * 根据类型获取公司信息详细信息
     */
    @ApiOperation("根据类型获取公司信息详细信息")
    @GetMapping(value = "/settingType/{settingType}")
    public AjaxResult getInfoBySettingType(@PathVariable("settingType") CompanyInformationEnum informationEnum) {
        return success(cnCompanyInformationService.getInfoBySettingType(informationEnum));
    }

    /**
     * 新增公司信息
     */
    @ApiOperation("新增公司信息")
    @PreAuthorize("@ss.hasPermi('system:information:add')")
    @Log(title = "公司信息", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody CnCompanyInformation cnCompanyInformation) {
        return toAjax(cnCompanyInformationService.insertCnCompanyInformation(cnCompanyInformation));
    }

    /**
     * 修改公司信息
     */
    @ApiOperation("修改公司信息")
    @PreAuthorize("@ss.hasPermi('system:information:edit')")
    @Log(title = "公司信息", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@Validated @RequestBody CnCompanyInformation cnCompanyInformation) {
        return toAjax(cnCompanyInformationService.updateCnCompanyInformation(cnCompanyInformation));
    }

    /**
     * 删除公司信息
     */
    @ApiOperation("删除公司信息")
    @ApiImplicitParam(name = "ids", value = "公司信息ID集合", required = true, dataType = "String", paramType = "path", dataTypeClass=String.class)
    @PreAuthorize("@ss.hasPermi('system:information:remove')")
    @Log(title = "公司信息", businessType = BusinessType.DELETE)
	@PostMapping("/batchDelete")
    public AjaxResult batchDelete(@RequestBody List<String> ids) {
        return toAjax(cnCompanyInformationService.deleteCnCompanyInformationByIds(ids));
    }
}
